﻿using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class Girl : Character {
    public Text m_ActionTurnText;
    public int ActionTurn { get; set;}
    private int ActionIndex { get; set;}
    private int MaxActionIndex { get; set; }

    public override void Init(Sys_Role data)
    {
        base.Init(data);
        MaxActionIndex = Data.SkillCycle.Split(',').Length;
        ActionTurn = Data.ActiveTurn;
        m_ActionTurnText.text = ActionTurn.ToString();
    }

    public IEnumerator PassActionTurn() {
        ActionTurn--;
        if (ActionTurn <= 0) {
            ActionTurn = Data.ActiveTurn;
            yield return StartCoroutine(Attack());
        }
        m_ActionTurnText.text = ActionTurn.ToString();
    }

    public void PassActionIndex()
    {
        ActionIndex++;
        if (ActionIndex >= MaxActionIndex)
        {
            ActionIndex = 0;
        }
    }

    public IEnumerator Attack() {
        Damage damage = new Damage(m_StarBox.m_Player);
        int skillId = int.Parse(Data.SkillCycle.Split(',')[ActionIndex]);
        var skill = ConfigController.Instance.GetConfig<Sys_EnemySkill>(skillId);
        if (skill.ReleaseStar != "0") {
            string[] releaseTeam = skill.ReleaseStar.Split(',');
            for (int i = 0; i < releaseTeam.Length; i++)
            {
                string[] value = releaseTeam[i].Split(':');
                int releaseNum = int.Parse(value[1]);
                for (int j = 0; j < releaseNum; j++)
                {
                    StarBox.SpecialStars.Add(ConfigController.Instance.GetConfig<Sys_Star>(int.Parse(value[0])));
                }
            }
        }
        
        float damageValue = Data.Att * skill.DamageRate / 100.0f;
        damage.AddDamage(Damage.DamageType.Chaos, damageValue);
        damage.Active();
        PassActionIndex();
        //暂时留到下一帧再退出，后面会结合动画播放来延迟
        yield return null;
    }

}
